package java05;


import java.util.Arrays;
import java.util.Scanner;

class PersonSortable implements Comparable<PersonSortable>{
	private String name;
	private int age;
	public int compareTo(PersonSortable p){
		if(!this.name.equals(p.name))
			return name.compareTo(p.name);
		else{
			if(this.age>p.age)
				return 1;
			else if(this.age == p.age)
				return 0;
			else
				return -1;
		}
	}

	@Override
	public String toString() {
		return name + "-" + age;
	}
	
	public PersonSortable(String name, int age){
		this.name = name;
		this.age = age;
	}
}

public class java1 {
	
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		PersonSortable[] persons = new PersonSortable[n];
		for(int i = 0; i < n ; i++ ){
			persons[i] = new PersonSortable(sc.next() , sc.nextInt());
		}
		Arrays.sort(persons);
		for(int i = 0; i < n ; i++ ){
			System.out.println(persons[i].toString());
		}
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
	}

}